package pro.softzhang.algo.lc300;

public class LC318_MaximumProductOfWorldLengths {
    public static void main(String[] args) {
        String[] words = new String[]{"a","ab","abc","d","cd","bcd","abcd"};
        int max = new Solution().maxProduct(words);
        System.out.println(max);
    }

    static class Solution {
        public int maxProduct(String[] words) {
            boolean[][] arr = new boolean[words.length][26];
            for (int i = 0; i < words.length; i++) {
                for (char c : words[i].toCharArray()) {
                    arr[i][c - 'a'] = true;
                }
            }

            int max = 0;
            for (int i = 0; i < words.length; i++) {
                for (int j = i + 1; j < words.length; j++) {
                    int k = 0;
                    for (; k < 26; k++) {
                        if(arr[i][k] && arr[j][k]) {
                            break;
                        }
                    }

                    if(k == 26) {
                        max = Math.max(max, words[i].length() * words[j].length());
                    }
                }
            }
            return max;
        }
    }

}